package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.bean.FilterPassageCondition;

@WebServlet("/FilterPassageServlet")
public class FilterPassageServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		//解决解码中文错误
		request.setCharacterEncoding("UTF-8");
		
		String city = request.getParameter("tcity");
		if(city != null && ( !city.equals("") ) ){
			FilterPassageCondition.city = city;
		}
		System.out.println("city"+city);
		
		String tcost = request.getParameter("tcost");
		System.out.println("tcost"+tcost);
		
		String tdays = request.getParameter("tdays");
		System.out.println("tdays"+tdays);
		
		
		switch(tcost){
		case "default" :
			FilterPassageCondition.mincost = 0;FilterPassageCondition.maxcost = (int)Float.POSITIVE_INFINITY;
	    	break; 
	    case "2" :
	    	FilterPassageCondition.mincost = 0;FilterPassageCondition.maxcost = 1000;
	    	break; 
	    case "3" :
	    	FilterPassageCondition.mincost = 1000;FilterPassageCondition.maxcost = 5000;
	    	break; 
	    case "4" :
	    	FilterPassageCondition.mincost = 5000;FilterPassageCondition.maxcost = 10000;
	    	break; 
	    case "5" :
	    	FilterPassageCondition.mincost = 10000;FilterPassageCondition.maxcost = (int)Float.POSITIVE_INFINITY;
	    	break; 	       
		}
		switch(tdays){
		case "default" :
			FilterPassageCondition.minday = 0;FilterPassageCondition.maxday = (int)Float.POSITIVE_INFINITY;
	    	break; 
	    case "2" :
	    	FilterPassageCondition.minday = 1;FilterPassageCondition.maxday = 3;
	    	break; 
	    case "3" :
	    	FilterPassageCondition.minday = 3;FilterPassageCondition.maxday = 7;
	    	break; 
	    case "4" :
	    	FilterPassageCondition.minday = 7;FilterPassageCondition.maxday = (int)Float.POSITIVE_INFINITY;
	    	break;      
		}
		//转发到成功页面
		request.getRequestDispatcher("/travelList.jsp?page=1").forward(request, response);
		
	
	}

}
